<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% 
	String ctx=request.getContextPath();
%>
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="<%=ctx%>/zenithsun/css/cut-imgList.css" type="text/css" />
<body>
<div class="modal fade bs-example-modal-lg" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">上传App—${basicdata.code}</h4>
      </div>
      <div class="modal-body" id="modalCore">
        <form class="form-horizontal" role="form" id="aeForm" name="aeForm">
          <fieldset>
            <!-- generate code start -->
            <input type="hidden" id="id" name="id" value="${basicdata.id}"/>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="comment">版本号</label>
              <div class="col-sm-8">
                <input id="comment" name="comment" class="form-control"  placeholder="必填项" value="${basicdata.comment}"/>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="comment">下载地址</label>
              <div class="col-sm-8">
                <input id="comment" name="comment" class="form-control"  value="${basicdata.remark}" readonly="readonly"/>
              </div>
            </div>
            <div class="form-group">
            	<label class="col-sm-2 control-label" for="comment">上传文件</label>
           		<div class="col-sm-4">
					<input id="selectPath" class="form-control"  readonly="readonly"/>
     			</div>
     			<div class="col-sm-3">
					<div class="chsoeImg">选择
					<c:if test="${basicdata.code=='IOS'}">
					IPA
					</c:if>
					<c:if test="${basicdata.code=='Android'}">
					APK
					</c:if>
					文件</div>
					<input type="file" id="crop_upload_file" name="file" <c:if test="${basicdata.code=='IOS'}">
					accept=".ipa"
					</c:if>
					<c:if test="${basicdata.code=='Android'}">
					accept=".apk"
					</c:if>
					/>
     			</div>
            </div>
			<!-- generate code end -->
          </fieldset>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <!-- <button type="button" class="btn btn-primary" onclick="submitSave('add');">保存</button> -->
        <button type="button" class="btn btn-primary" id="crop_upload">保存</button>
      </div>
    </div>
  </div>
</div>
<script src="<%=ctx%>/zenithsun/plugins/ajaxfileupload.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
	$("#crop_upload").click(function(){
		var sepath=$("#selectPath").val();
		if(sepath!=null&&sepath.length>0){
			ajaxFileUpload();
		}else{
			var type="${basicdata.code}";
			var fileType="";
			if(type=="IOS"){
				fileType="IPA";
			}else if(type=="Android"){
				fileType="APK";
			}
			bootbox.alert("<h4>请先上传格式为"+fileType+"的文件</h4>", function(){});
		}
	});
	
	$("#crop_upload_file").change(function(){
		var vpath=$(this).val();
		var flag=validateFile(vpath);
		if(flag){
			$("#selectPath").val(vpath);
		}
	});
});
function validateFile(path){
	var flag=false;
	var type="${basicdata.code}";
	path=path.substring(path.lastIndexOf(".")+1,path.length).toUpperCase();
	var fileType="";
	if(type=="IOS"){
		fileType="IPA";
		if(path==fileType){
			flag=true;
		}
	}else if(type=="Android"){
		fileType="APK";
		if(path==fileType){
			flag=true;
		}
	}
	if(!flag){
		bootbox.alert("<h4>"+type+"对应的文件格式是："+fileType+"</h4>", function(){});
	}
	return flag;
}

function getUploadParam(){
	var urlParam="";
	urlParam="?baId=${basicdata.id}";
	urlParam+="&version="+$("#comment").val();
	return urlParam;
}
function ajaxFileUpload() {
    $.ajaxFileUpload
    (
        {
            url: '<%=ctx%>/path/basicdata/uploadApp'+getUploadParam(), //用于文件上传的服务器端请求地址
            secureuri: false, //一般设置为false
            fileElementId: 'crop_upload_file', //文件上传空间的id属性  <input type="file" id="file" name="file" />
            dataType: 'json', //返回值类型 一般设置为json
            success: function (data, status)  //服务器成功响应处理函数
            {
            	bootbox.alert("<h4>操作成功</h4>", function(){$("#editModal").modal("hide");});
            	
            },
            error: function (data, status, e)//服务器响应失败处理函数
            {
            	//bootbox.alert("<h4>操作失败,原因：" + data.content + "</h4>", function(){});
            }
        }
    )
    return false;
}
</script>
</body>
</html>

